package com.qing.study.controller;

import com.qing.study.comm.Result;
import com.qing.study.mapper.WitticismSentenceMapper;
import com.qing.study.pojo.WitticismSentence;
import com.qing.study.service.WitticismSentenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("witticismSentence")
@Api(tags = "名言警句相关操作")
public class WitticismSentenceController {
    @Resource
    private WitticismSentenceService witticismSentenceService;
    @Resource
    private WitticismSentenceMapper witticismSentenceMapper;

    @ApiOperation("发送请求获取数据并插库")
    @GetMapping("getLinkDataAndAdd")
    public Result getLinkDataAndAdd(){
        return witticismSentenceService.getLinkDataAndAdd();
    }

    @ApiOperation("使用mapper.xml插入id为1的数据")
    @PostMapping("saveId1FromXml")
    public Result saveId1FromXml(@RequestBody WitticismSentence witticismSentence){
        int i = witticismSentenceMapper.saveOneData(witticismSentence);
        if(i>=1){
            return Result.ok("新增成功！");
        }else{
            return Result.error(500,"新增失败！");
        }
    }
}
